package com.imooc.web.config;

import java.util.ArrayList;
import java.util.List;

import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

import com.imooc.web.filter.TimeFilter;
import com.imooc.web.interceptor.TimeInterceptor;

/**
 * 引入第三方过滤器时，没有@Component,则自定义配置将第三方过滤器加进来
 * @author Jon
 *
 */
//@Configuration
public class WebConfig extends WebMvcConfigurerAdapter{
	
	//@Autowired
	private TimeInterceptor timeInterceptor;

	//@Override
	public void addInterceptors(InterceptorRegistry registry) {
		registry.addInterceptor(timeInterceptor);
	}
		
	//@Bean
	public FilterRegistrationBean timeFilter() {
		FilterRegistrationBean bean = new FilterRegistrationBean();
		//将自定义过滤器加进来
		TimeFilter timeFilter = new TimeFilter();
		bean.setFilter(timeFilter);
		//设置相关属性
		List<String> urls = new ArrayList<String>();
		urls.add("/*");
		bean.setUrlPatterns(urls);
		return bean;
	}
}
